<?php
namespace Wap\Service;

class CookieService
{
	public static function fetch_arr_by_prefix( $prefix = "" )
	{
		$result	=	array();
		if( empty( $prefix ) ){
			return $result;
		}

		foreach( $_COOKIE as $key => $value ){
			if( strpos( $key, $prefix ) == 0 ){
				$startP	=	strlen( $prefix ) + 1;
				$startQ	=	strlen( $key ) - $startP;
				$newKey	=	substr( $key, $startP, $startQ );

				$result[ $newKey ]	=	$value;
			}
		}
		return $result;
	}

	public static function expire_by_prefix( $prefix = "", $name="" )
	{
		if( !empty( $name ) ){
			cookie( $prefix.$name, null );
			return;
		}

		foreach( $_COOKIE as $key => $value ){	
			if( strpos( $key, $prefix ) == 0 ){
				setcookie( $key, $value, time()-24 * 60 * 60 );
			}
		}
		
	}
}
?>
